//
//  TopSelling.swift
//  MyCookbook
//
//  Created by liaokylin on 2024/10/21.
//

import SwiftUI

struct TopSelling: View {
    var items = ["全部","时令果蔬","地方特色","早餐","方便速食","肉禽水产","粮油调味","零食","酒水乳饮","厨房用品"]
    var layout = [
        GridItem(.adaptive(minimum: 200, maximum: 300)),
        GridItem(.adaptive(minimum: 200, maximum: 300))
    ]
    var body: some View {
        VStack(alignment:.leading){
            Text("7天销量榜").font(.largeTitle).bold()
            ScrollView(.horizontal,showsIndicators: false){
                HStack{
                    ForEach(items,id:\.self) { item in
                        Text(item)
                            .foregroundColor(.gray)
                            .padding(EdgeInsets(top: 12, leading: 10, bottom: 12, trailing: 10))
                            .background(.gray.opacity(0.1))
                            .cornerRadius(10)
                          
                    }
                }
            }
            ScrollView{
                LazyVGrid(columns: layout) {
                    ForEach(1...10,id:\.self) { _ in
                        goods()
                    }
                }
            }
        }
    }
    
    @ViewBuilder func goods() -> some View {
        VStack(alignment:.leading){
            Image("1").resizable()
                .frame(maxWidth: .infinity,maxHeight: 200)
            Text("贝果").lineLimit(1)
            HStack{
                Text("$39.9起购")
                    .font(.caption)
                    .foregroundColor(.pink)
                Spacer()
                Text("7天销量 786")
                    .font(.caption)
                    .foregroundColor(.gray.opacity(0.8))
            }
        }
    }
}

#Preview {
    TopSelling()
}
